package com.sls.web.manager.action.ekhui;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.game.client.OperatorClient;
import com.sls.web.manager.game.client.ResisterClient;
import com.sls.web.manager.game.client.TraderClient;
import com.sls.web.manager.game.pojo.ekhui.Account;
import com.sls.web.manager.game.pojo.ekhui.Area;
import com.sls.web.manager.game.pojo.ekhui.City;
import com.sls.web.manager.game.pojo.ekhui.Operator;
import com.sls.web.manager.game.pojo.ekhui.Province;
import com.sls.web.manager.game.pojo.ekhui.Trader;
import com.sls.web.manager.game.querybean.TraderQuery;
import com.sls.web.manager.page.Pagination;
import com.sls.web.manager.pojo.UserInfoVO;

public class TraderAction extends SuperAction{
	private Logger log = LoggerFactory.getLogger(DepositAction.class) ;
	private List<Trader> traderList  ;
	private Pagination<Trader> page;
	private Trader trader ;
	private Operator operator ;
	private TraderQuery traderQuery ;
	private String startTime ;
	private String endTime ;
	private int recordCount ;
	private List<Province> provinceList ;
	private List<City> cityList ;
	private List<Area> areaList ;
	private Province province ;
	private Account account ;
	private City city ; 

	public String list(){
		if(trader == null){
			trader = new Trader() ;
		}
		if (traderQuery == null) {
			traderQuery = new TraderQuery();
			traderQuery.setPageSize(Constants.INIT_PAGESIZE);
			traderQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
		}
		TraderClient client = TraderClient.getInstance() ;
		UserInfoVO userInfoVO = getCurrentOperator() ;
		recordCount = client.getTraderCount(userInfoVO, trader) ;
		if(page == null){
			page = new Pagination<Trader>(traderQuery.getCurrentPage() , recordCount , traderQuery.getPageSize()) ;
		}
		
		traderList = client.getTraderList(userInfoVO, trader, traderQuery.getCurrentPage(), traderQuery.getPageSize()) ;
		page.setList(traderList) ;
		page.setRowCount(recordCount) ;
		
		return "list" ;
	}
	public String checkTraderName(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		TraderClient client = TraderClient.getInstance() ;
		Trader resTrader = client.getTraderByName(userInfoVO , trader) ;
		message = String.valueOf(resTrader != null) ;
		return "ajax" ;
	}
	public String checkUserName(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		OperatorClient client = OperatorClient.getInstance() ;
		Operator registerOperator = client.getOperatorByLogin(userInfoVO , operator) ;
		message = String.valueOf(registerOperator != null) ;
		return "ajax" ;
	}
	public String getCitys(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		ResisterClient client = ResisterClient.getInstance() ;
		cityList = client.getCityList(userInfoVO, province) ;
		Gson gson = new Gson() ;
		message = gson.toJson(cityList) ;
		return "ajax" ;
	}
	public String getArea(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		ResisterClient client = ResisterClient.getInstance() ;
		areaList = client.getAreaList(userInfoVO, city) ;
		Gson gson = new Gson() ;
		message = gson.toJson(areaList) ;
		return "ajax" ;
	}
	public String add(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		ResisterClient client = ResisterClient.getInstance() ;
		provinceList = client.getProvinceList(userInfoVO) ;
		return "add" ;
	}
	public String addComplete(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		ResisterClient client = ResisterClient.getInstance() ;
		Trader parentTrader = new Trader() ;
		trader = trader.saveTrader(parentTrader) ;
		message = String.valueOf(client.register(userInfoVO, trader, operator , account)) ;
		return "ajax" ;
	}
	public String tocheck(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		TraderClient client = TraderClient.getInstance() ;
		trader = client.getTrader(userInfoVO, trader) ;
		return "tocheck" ; 
	}
	public String check(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		TraderClient client = TraderClient.getInstance() ;
		message = String.valueOf(client.checkTrader(userInfoVO, trader)) ;
		return "ajax" ;
	}
	public String detail(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		TraderClient client = TraderClient.getInstance() ;
		trader = client.getTrader(userInfoVO, trader) ;
		return "detail" ;
	}
	public String updateStatus(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		TraderClient client = TraderClient.getInstance() ;
		message = String.valueOf(client.updateTraderStatus(userInfoVO, trader)) ;
		return "ajax" ;
	}
	public List<Trader> getTraderList() {
		return traderList;
	}
	public void setTraderList(List<Trader> traderList) {
		this.traderList = traderList;
	}
	public Pagination<Trader> getPage() {
		return page;
	}
	public void setPage(Pagination<Trader> page) {
		this.page = page;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public int getRecordCount() {
		return recordCount;
	}
	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}
	public Trader getTrader() {
		return trader;
	}
	public void setTrader(Trader trader) {
		this.trader = trader;
	}
	public TraderQuery getTraderQuery() {
		return traderQuery;
	}
	public void setTraderQuery(TraderQuery traderQuery) {
		this.traderQuery = traderQuery;
	}
	public List<Province> getProvinceList() {
		return provinceList;
	}
	public void setProvinceList(List<Province> provinceList) {
		this.provinceList = provinceList;
	}
	public List<City> getCityList() {
		return cityList;
	}
	public void setCityList(List<City> cityList) {
		this.cityList = cityList;
	}
	public List<Area> getAreaList() {
		return areaList;
	}
	public void setAreaList(List<Area> areaList) {
		this.areaList = areaList;
	}
	public Province getProvince() {
		return province;
	}
	public void setProvince(Province province) {
		this.province = province;
	}
	public City getCity() {
		return city;
	}
	public void setCity(City city) {
		this.city = city;
	}
	public Operator getOperator() {
		return operator;
	}
	public void setOperator(Operator operator) {
		this.operator = operator;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
}
